﻿using System;
using ZX.Common;
using ZX.DBModule;
using ZX.Web.UI.Controls;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.TR.Library;
using ZX.TR.Bussiness;
using System.Threading;
using ZX.EHR.Library;
using ZX.BLL.Extend;
using System.Collections.Generic;

namespace ZX.WebApp.TR
{
    public partial class QSView : BasePage
    {

        public bool bl = false;
        BTrQuestionnaireSubject btqs = new BTrQuestionnaireSubject();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                V_TrQuestionnaire vtq = new V_TrQuestionnaire();
                V_TrSendQuestion vtsq = new V_TrSendQuestion();
                string strId = Request.QueryString["QID"];
                if (strId != "")
                {
                    vtsq = btqs.GetAllTrSendQuestionInfoById(new Guid(strId));
                    strId = vtsq == null ? "00000000-0000-0000-0000-000000000000" : vtsq.TrQuestionnaireID.ToString();
                    vtq = btqs.GetAllQuestionnaireInfoById(new Guid(strId));
                    if (vtq != null)
                    {
                        lblWjName.Text = vtq.QuestionnaireName;
                        txtAim.Text = vtq.QAim;
                        txtDept.Text = vtq.DeptName;
                        txtKnown.Text = vtq.QNotice;
                        txtPoint.Text = vtq.PointSum.ToString();
                        txtSum.Text = vtq.SubjectSum.ToString();
                        txtTime.Text = vtq.QTimeLength.ToString();
                        bind(vtq.TrQuestionnaireID, 9999, 0);
                    }
                }
            }
        }
        protected string GetFormat(object obj)
        {
            string strReturn = "";
            strReturn = obj == null ? "" : obj.ToString().Replace("###","");
            return strReturn;
        }
        private void bind(Guid guid, int topNum, int pageNum)
        {
            if (Request.QueryString["uid"] != null)
            {
                IList<V_TrExam> vteList = btqs.GetExamListById(guid);
                rptList.DataSource = vteList;
                rptList.DataBind();
            }
            else
            {
                DatUser duser = Session["User"] as DatUser;
                IList<V_TrExam> vteList = btqs.GetExamListById(guid);
                rptList.DataSource = vteList;
                rptList.DataBind();
            }


        }

        /// <summary>
        /// 控件绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label lblType = e.Item.FindControl("lblType") as Label;
            bl = false;
            if (lblType != null && (lblType.Text == "单选题" || lblType.Text == "多选题"))
            {
                Repeater rpt = e.Item.FindControl("rptItem") as Repeater;
                HiddenField hdnFld = e.Item.FindControl("hdnQid") as HiddenField;
                if (hdnFld != null)
                {
                    rpt.DataSource = btqs.GetSubjectInfoToItem(new Guid(hdnFld.Value));
                    rpt.DataBind();
                    bl = true;
                }

            }
        }
    }
}